//
//  ZPaySucceedViewController.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/16.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "ZPaySucceedViewController.h"
#import "ZPayResultHeaderView.h"
#import "ZPayResultFootView.h"
#import "ZPayViewCell.h"//

#import "ZDoctorReplyViewController.h"
#import "ZAppraiseViewController.h"
//#import "ZAlreadyViewController.h"
#import "ZMyAskViewController.h"
#import "HomeViewController.h"

static NSString * const ZPaySucceedIdentifier = @"ZPaySucceedIdentifier";
@interface ZPaySucceedViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate> {
    ZPayResultHeaderView * _headerView;
    ZPayResultFootView * _footView;
    NSArray * _titleArray;
}
@property (nonatomic,strong) UITableView * succeedView;
@end

@implementation ZPaySucceedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"支付结果";
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.delegate = self;
    [self initialzeDatas];
    [self initlizeInterface];
}
- (void)initialzeDatas {
    _titleArray = @[@"订单号:",@"交易方式:",@"交易时间:",@"交易金额:"];
}
- (void)initlizeInterface {
    [self makeALLSubView];
    [self addALLSubView];
}
- (void)makeALLSubView {
    _headerView = [[ZPayResultHeaderView alloc] init];
    _headerView.imageView.image = [UIImage imageNamed:@"pay_Success"];
    _headerView.titleLabel.text = @"恭喜支付成功";
    _footView = [[ZPayResultFootView alloc] init];
    [_footView.assessBtn setTitle:@"立即评价" forState:UIControlStateNormal];
    [_footView.assessBtn addTarget:self action:@selector(goAppraiseVCAction:) forControlEvents:UIControlEventTouchUpInside];
    [_footView.backBtn addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];

}
-(void)addALLSubView {
    [self.view addSubview:_headerView];
    [self.view addSubview:self.succeedView];
    [self.view addSubview:_footView];
    [self makeALLSubViewMasnoy];
}
-(void)makeALLSubViewMasnoy {
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.top.equalTo(self.view);
        make.height.offset(195*ysIZE);
    }];
    [_footView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.width.equalTo(self.succeedView);
        make.top.equalTo(self.succeedView.mas_bottom).offset(5*ysIZE);
        make.height.offset(40*ysIZE);
    }];
}

// 进入评价的界面
- (void)goAppraiseVCAction:(UIButton *)sender {
    ZAppraiseViewController * ZAVC = [[ZAppraiseViewController alloc] init];
    ZAVC.order_num = self.order_num;
    [self.navigationController pushViewController:ZAVC animated:YES];
}

// 返回回复页的按钮
- (void)backButtonAction:(UIButton *)sender {
    NSArray *temArray = self.navigationController.viewControllers;
    for (UIViewController * vc in temArray) {
        if (_isHome == YES) {
            if ([vc isKindOfClass:[HomeViewController class]]) {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"paySuess" object:nil];
                [self.navigationController popToViewController:vc animated:YES];
                return;
            }
        }
        if ([vc isKindOfClass:[ZDoctorReplyViewController class]] || [vc isKindOfClass:[ZMyAskViewController class]] ) {
            [self.navigationController popToViewController:vc animated:YES];
        }
    }
}
//表格视图协议
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZPayViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ZPaySucceedIdentifier];
    cell.theTitlelabel.text  = _titleArray[indexPath.row];
    cell.theTextLabel.text = @"";
    return cell;
}


- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    
    self.navigationItem.hidesBackButton = isShowHomePage;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

// lazy
- (UITableView *)succeedView {
    if (_succeedView) {
        return _succeedView;
    }
    _succeedView = [[UITableView alloc] initWithFrame:CGRectMake(0, 195*ysIZE, SCREEN_Width, 180*ysIZE) style:UITableViewStylePlain];
    _succeedView.delegate = self ;
    _succeedView.dataSource = self;
    _succeedView.rowHeight = 45*ysIZE;
    _succeedView.separatorStyle = NO;
    [_succeedView registerClass:[ZPayViewCell class] forCellReuseIdentifier:ZPaySucceedIdentifier];
    return _succeedView;
}


@end
